home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / gdevdfax.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-27  |  3.3 KB  |  112 lines

  1. /* Copyright (C) 1994, 1995 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevdfax.c */
  20. /* DigiBoard fax device. */
  21. /***
  22.  *** Note: this driver is maintained by a user: please contact
  23.  ***       Rick Richardson (rick@digibd.com) if you have questions.
  24.  ***/
  25. #include "gdevprn.h"
  26. #include "strimpl.h"
  27. #include "scfx.h"
  28.  
  29. /* Import the key routines from gdevtfax.c. */
  30. int gdev_fax_open(P1(gx_device *));
  31. void gdev_fax_init_state(P2(stream_CFE_state *, const gx_device_printer *));
  32. int gdev_fax_print_page(P3(gx_device_printer *, FILE *, stream_CFE_state *));
  33.  
  34. /* Define the device parameters. */
  35. #define X_DPI 204
  36. #define Y_DPI 196
  37.  
  38. /* The device descriptors */
  39.  
  40. private dev_proc_open_device(dfax_prn_open);
  41. private dev_proc_print_page(dfax_print_page);
  42.  
  43. struct gx_device_dfax_s {
  44.     gx_device_common;
  45.     gx_prn_device_common;
  46.     long pageno;
  47.     uint iwidth;        /* width of image data in pixels */
  48. };
  49. typedef struct gx_device_dfax_s gx_device_dfax;
  50.  
  51. private gx_device_procs dfax_procs =
  52.   prn_procs(dfax_prn_open, gdev_prn_output_page, gdev_prn_close);
  53.  
  54. gx_device_dfax far_data gs_dfaxlow_device =
  55. {   prn_device_std_body(gx_device_dfax, dfax_procs, "dfaxlow",
  56.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  57.     X_DPI, Y_DPI/2,
  58.     0,0,0,0,            /* margins */
  59.     1, dfax_print_page)
  60. };
  61.  
  62. gx_device_dfax far_data gs_dfaxhigh_device =
  63. {   prn_device_std_body(gx_device_dfax, dfax_procs, "dfaxhigh",
  64.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  65.     X_DPI, Y_DPI,
  66.     0,0,0,0,            /* margins */
  67.     1, dfax_print_page)
  68. };
  69.  
  70. #define dfdev ((gx_device_dfax *)dev)
  71.  
  72. /* Open the device, adjusting the paper size. */
  73. private int
  74. dfax_prn_open(gx_device *dev)
  75. {    dfdev->pageno = 0;
  76.     return gdev_fax_open(dev);
  77. }
  78.  
  79. /* Print a DigiFAX page. */
  80. private int
  81. dfax_print_page(gx_device_printer *dev, FILE *prn_stream)
  82. {    stream_CFE_state state;
  83.     static char hdr[64] = "\000PC Research, Inc\000\000\000\000\000\000";
  84.     int code;
  85.  
  86.     gdev_fax_init_state(&state, dev);
  87.     state.EndOfLine = true;
  88.     state.EncodedByteAlign = true;
  89.  
  90.     /* Start a page: write the header */
  91.     hdr[24] = 0; hdr[28] = 1;
  92.     hdr[26] = ++dfdev->pageno; hdr[27] = dfdev->pageno >> 8;
  93.     if (dev->y_pixels_per_inch == Y_DPI)
  94.         { hdr[45] = 0x40; hdr[29] = 1; }    /* high res */
  95.     else
  96.         { hdr[45] = hdr[29] = 0; }        /* low res */
  97.     fseek(prn_stream, 0, SEEK_END);
  98.     fwrite(hdr, sizeof(hdr), 1, prn_stream);
  99.  
  100.     /* Write the page */
  101.     code = gdev_fax_print_page(dev, prn_stream, &state);
  102.  
  103.     /* Fixup page count */
  104.     fseek(prn_stream, 24L, SEEK_SET);
  105.     hdr[24] = dfdev->pageno; hdr[25] = dfdev->pageno >> 8;
  106.     fwrite(hdr+24, 2, 1, prn_stream);
  107.  
  108.     return code;
  109. }
  110.  
  111. #undef dfdev
  112.